set more off
set matsize 800

* log using may06_realexpt_edcdf_cluster.log, replace
* log using may06_fakeexpt_edcdf_cluster_1433.log, replace
* log using may06_fakeexpt_edcdf_cluster_3453.log, replace
log using may06_fakeexpt_edcdf_cluster_4463.log, replace

use prdescent2005

/*
keep if yob >= 1924 & yob <= 1943
gen young = yob > 1933
gen treat = actual_treat
*/


/*
keep if yob >= 1914 & yob <= 1933
gen young = yob > 1923
sort yob yrssch
merge yob yrssch using fake_treat_1433
tab _m
keep if _merge == 3
gen treat = fake_treat
drop _m
*/


/*
keep if yob >= 1934 & yob <= 1953
gen young = yob > 1943
sort yob yrssch
merge yob yrssch using fake_treat_3453
tab _m
keep if _merge == 3
gen treat = fake_treat
drop _m
*/


keep if yob >= 1944 & yob <= 1963
gen young = yob > 1953
sort yob yrssch
merge yob yrssch using fake_treat_4463
tab _m
keep if _merge == 3
gen treat = fake_treat
drop _m


drop if cenyr == 1970
* drop if cenyr == 1980
keep if bornpr

replace yrssch_1990 = yrssch if cenyr == 1990 & liveinus

gen yrssch_all = .
replace yrssch_all = yrssch_1990 if cenyr == 1990
replace yrssch_all = 0 if yrssch == 0 & cenyr == 1980
replace yrssch_all = 3 if (yrssch >= 1 & yrssch <= 4) & cenyr == 1980
replace yrssch_all = 7 if (yrssch >= 5 & yrssch <= 8) & cenyr == 1980
replace yrssch_all = yrssch if (yrssch >= 9 & yrssch <= 12) & cenyr == 1980
replace yrssch_all = 14 if (yrssch >= 13 & yrssch <= 15) & cenyr == 1980
replace yrssch_all = yrssch if yrssch == 16 & cenyr == 1980
replace yrssch_all = 18 if yrssch > 16 


gen groupid = yob*100 + yrssch_all 


sort yob yrssch_all
merge yob yrssch_all using cdfedless
drop if _merge == 2
gen cdfedlesssq = cdfedless^2



table young if bornpr , c(mean actual_t)
table young edmore4 if bornpr , c(mean actual_t)
table yrssch_all young if bornpr , c(mean actual_t)

table young if bornpr , c(mean pot_t)
table young edmore4 if bornpr , c(mean pot_t)
table yrssch_all young if bornpr , c(mean pot_t)

tab yrssch_all if bornpr & ~young
tab yrssch_all if bornpr & young

tab yrssch_all if bornpr & ~young & ~liveinus
tab yrssch_all if bornpr & young & ~liveinus

tab yrssch_all if bornpr & ~young & liveinus
tab yrssch_all if bornpr & young & liveinus



gen roundtreat = round(treat,1)


gen dtreat1 = roundtreat==1
gen dtreat2 = roundtreat==2
gen dtreat3 = roundtreat==3
gen dtreat4 = roundtreat==4
gen dtreat5 = roundtreat==5
gen dtreat6 = roundtreat==6
gen dtreat7 = roundtreat==7
gen dtreat8 = roundtreat==8


tab age, gen(dage)
drop dage1


gen agesq = age^2 

gen potex = age-yrssch-6
gen potexsq = potex^2

gen dummy1990 = cenyr == 1990

* global ageexp "age agesq potex potexsq female"
global ageexp "dage* potex potexsq dummy1990 cdfed* female"

tab yob, gen(dyob)
drop dyob1

tab yrssch_all, gen(deduc)
drop deduc1 

reg speakeng dtreat* dyob* deduc* $ageexp , cluster(groupid)
testparm dtreat1-dtreat8

reg engwell dtreat* dyob* deduc* $ageexp , cluster(groupid)
testparm dtreat1-dtreat8

reg speakeng dtreat* dyob* deduc* $ageexp liveinus , cluster(groupid)
testparm dtreat1-dtreat8

reg engwell dtreat* dyob* deduc* $ageexp liveinus , cluster(groupid)
testparm dtreat1-dtreat8

reg speakeng dtreat* dyob* deduc* $ageexp  if ~liveinus, cluster(groupid)
testparm dtreat1-dtreat8

reg engwell dtreat* dyob* deduc* $ageexp  if ~liveinus, cluster(groupid)
testparm dtreat1-dtreat8


* linear models
sum treat
sum treat if treat > 0

reg speakeng treat dyob* deduc* $ageexp , cluster(groupid)
reg engwell treat dyob* deduc* $ageexp , cluster(groupid)

reg speakeng treat dyob* deduc* $ageexp liveinus , cluster(groupid)
reg engwell treat dyob* deduc* $ageexp liveinus , cluster(groupid)

reg speakeng treat dyob* deduc* $ageexp  if ~liveinus, cluster(groupid)
reg engwell treat dyob* deduc* $ageexp  if ~liveinus, cluster(groupid)



log close




